package org.example.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 书架
 *
 * @author lzf 2024/3/24 23:38:37
 */
public class BookShelf implements Aggregate {
    private final List<Book> books;

    public BookShelf(int initialCapacity) {
        this.books = new ArrayList<>(initialCapacity);
    }

    public BookShelf() {
        this.books = new ArrayList<>();
    }

    public Book getBookAt(int index) {
        return books.get(index);
    }

    public void appendBook(Book book) {
        this.books.add(book);
    }

    public int getLength() {
        return this.books.size();
    }


    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
